package servlet.peopel;

import dao.PeopleDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by young on 2017/6/24.
 */
@WebServlet(name = "DeletePeople", urlPatterns = "/deletePeople")
public class DeletePeople extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setHeader("content-type", "text/html;charset=UTF-8");
        String id = request.getParameter("id");
        PeopleDao peopleDao = new PeopleDao();
        int row = peopleDao.deletePeople(Integer.parseInt(id));
        if (row != 0) {
            response.sendRedirect("/peopleManger.jsp");
        } else {
            response.sendRedirect("/errorPage.jsp");
        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
